using System;
using System.Windows.Media;
using System.Xml.Serialization;
using Elca.MvvmHelpers;

namespace ULSDeobfuscator {
    public class AnnotationInfo : BaseNotifyableObject {
        private string _annotation;
        private int _startPercent;
        private bool _isVisible;

        public int StartPercent {
            get { return _startPercent; }
            set {
                _startPercent = value;
                OnPropertyChanged("StartPercent");
            }
        }

        public int HeightPercent { get; set; }

        public Brush Brush { get; set; }
        //public Color LightColor { get; set; }
        //public Color DarkColor { get; set; }

        public string Annotation {
            get { return _annotation; }
            set {
                _annotation = value;
                OnPropertyChanged("Annotation");
                OnPropertyChanged("Text");
            }
        }

        public string Text => AssociatedEntry.DisplayedDay + Environment.NewLine + Annotation;

        public LogEntry AssociatedEntry { get; set; }

        public bool IsVisible {
            get { return _isVisible; }
            set {
                _isVisible = value;
                OnPropertyChanged("IsVisible");
            }
        }

        /// <summary>
        /// True for 'real' annotations, false for search bookmarks
        /// </summary>
        public bool IsPersistent { get; set; }

        public bool IsSearchAnnotation => !IsPersistent;
        public bool IsUserAnnotation => IsPersistent;
    }

    public class AnnotationInfoSerialized {
        
        public string Annotation { get; set; }

        public DateTime DateTime { get; set; }

        /// <summary>
        /// Storing the date of the log entry is not enough as there may be several entries
        /// </summary>
        public string LogText { get; set; }

        public int Version { get; set; } = 1;

        /// <summary>
        /// Default constructor needed by XML serialization
        /// </summary>
        public AnnotationInfoSerialized() { }

        public AnnotationInfoSerialized(AnnotationInfo ai) {
            Annotation = ai.Annotation;
            LogText = ai.AssociatedEntry.Message;
            DateTime = ai.AssociatedEntry.Day;
        }

        public AnnotationInfo ToAnnotationInfo() {

            AnnotationInfo ai = new AnnotationInfo {
                Annotation = Annotation,
            };

            return ai;
        }
    }
}